import { runtimeConfig } from '../../configs/runtimeConfig'
import { chatHandlerMap } from './chatHandler'

export const generateArticleSummary = async (content: string) => {
    const currentSDK = runtimeConfig.writingChatModel
        .sdk as keyof typeof chatHandlerMap

    const chatHandle = chatHandlerMap[currentSDK]

    const response = await chatHandle(
        [
            {
                type: 'system',
                content: `你是一个文章总结助手，你需要总结出文章的摘要。
长度要求：
不要超过100字，内容不要太多，只需要一个段落即可。

输出格式：
本文主要介绍了{summary}。
`,
            },
            { type: 'user', content },
        ],
        runtimeConfig.writingChatModel
    )
    let res = ''
    // ctx.body = stream
    for await (const part of response) {
        // stream.write(`event: message\ndata: ${part.message.content}\n\n`)
        // stream.write(`data: ${part.message.content}\n\n`)
        res += part
    }
    console.log('res', res)
    return res
}
